home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / LFLTS / LATFIR1.HLP < prev    next >
Text File  |  1989-01-24  |  6KB  |  147 lines

  1.          Name: LATFIR1.ASM
  2.          Type: Assembler Macro
  3.       Version: 1.0
  4.   Last Change:  8-Aug-86
  5.  
  6.   Description: Lattice FIR Filter Assembler Macro
  7.  
  8.  This macro implements a lattice fir filter using reflection coefficients.
  9.  
  10.    BACKGROUND
  11.  
  12.    The basic section of a FIR lattice filter is shown in Figure 1.
  13.  
  14.             >-------------------------------(+)----------->
  15.             f[j-1](n)               \       ^            f[j](n)
  16.                                      \     /
  17.                                       \   k[j]
  18.                                        \ /
  19.                                         /
  20.                                        /  k[j]
  21.                                       /    \
  22.                                      /      v
  23.            >------1/z----------------------(+)----------->
  24.       b[j-1](n)       b[j-1](n-1)                      b[j](n)
  25.  
  26.                                     Figure 1
  27.  
  28.   The reference [j] indicates the jth stage  and  the  reference
  29.   (n)  indicates  the  sample  time.  The equations for a filter
  30.   section are:
  31.  
  32.                   f[j](n)= f[j-1](n) + k[j]*b[j-1](n-1)
  33.                   b[j](n)= b[j-1](n-1) + k[j]*f[j-1](n)
  34.  
  35.   The signals f(n) and b(n)  are  commonly  referred  to  as  the
  36.   forward  and  backward  prediction residuals respectively.
  37.  
  38.    IMPLEMENTATION
  39.  
  40.   A third order lattice FIR filter is shown in Figure 2.
  41.             T
  42.         |--->----->---(+)-->----->----(+)-->----->----(+)----> B (out)
  43.         |      |       ^      |        ^      |        ^
  44.         |      |      /       |       /       |       /
  45.         |       \    k1        \     k2        \     k3
  46.         ^        \  /           \   /           \   /
  47.         |          /               /               /
  48.    B >--|         /\              /\              /\
  49.    (in) |        /  \            /  \            /  \
  50.         v       /    k1         /    k2         /    k3
  51.         |       |     \         |     \         |     \
  52.         |       |      v        |      v        |      v
  53.         |- 1/z ---->--(+)- 1/z ---->--(+)- 1/z ---->--(+)-----
  54.                 S1               S2              S3         Sx
  55.                                  Figure 2
  56.    For the filter shown, the pointers R0 and R4  are  initialized
  57.   to point to the buffers as shown:
  58.  
  59.          R0                 R4
  60.         |                  |
  61.         v                  v
  62.     x:  S1 S2 S3 Sx     y: k1 k2 k3 kx
  63.          M0=3 (mod 4)       M4=3 (mod 4)
  64.  
  65.   The register R0 is initialized to point to the  start  of  the
  66.   state  variable  buffer  and R4 is initialized to point to the
  67.   first k coefficient of the filter.  The modulo  registers  are
  68.   set  to  the  number  of  coefficients  in the filter (in this
  69.   example there are three).  Note that the modulo  storage  area
  70.   is equal to the number of filter coefficients+1.
  71.  
  72.   The input sample is put in the B register and then the  filter
  73.   macro  is called.  The result of the filtering operation is in
  74.   B.  The state 'sx' is an unused state which  aids  calculation
  75.   efficiency.   (Actually,  the  value  sx  after  a  sample  is
  76.   filtered is the output of the lower leg of  the  filter.)  The
  77.   reflection coefficient 'kx' is an unused dummy value.
  78.  
  79.   To use the filter, it is assumed the registers R0, R4, M0  and
  80.   M4 have been properly initialized.  The input sample is put in
  81.   register B and the filter is called as:
  82.  
  83.               latfir order               ;call fir lattice filter
  84.  
  85.   where 'latfir' is the macro name and 'order' is the number  of
  86.   k coefficients.
  87.  
  88.   FILTER OPERATION
  89.  
  90.   The filter operation can be described (refer to Figure  2  and
  91.   the macro 'latfir1' in the DSPLIB):
  92.  
  93.    1.  The input sample is in register B.  This input sample will
  94.       be  the  first  state  S1 at the next sample time and will
  95.       initialize the T value.
  96.  
  97.    2.  The first MOVE instruction saves the input  sample  to  be
  98.       the  first state S1 for the next sample and increments the
  99.       pointer R0 to the next state.  The first k coefficient  k1
  100.       is  loaded  into  y0  and the pointer R4 is incremented to
  101.       point to the next coefficient.
  102.  
  103.    3.  The loop will make as many passes of the filter kernel  as
  104.       there are coefficients in the filter.
  105.  
  106.    4.  The old state S1 is loaded into accumulator A so that  the
  107.       the  bottom  b[j](n)  can be computed (see Figure 1).  The
  108.       current value of T (in register B) is moved into a product
  109.       register so it can be multiplied by the k coefficient.
  110.  
  111.    5.  The value b[j](n) is now computed by the first MAC.  The T
  112.       value  in  Y1 is multiplied by the k coefficient in Y0 and
  113.       added to the value of the previous state (A).  This  value
  114.       will  be  the  value  of S2 for the next sample time.  The
  115.       value in register A (the state  value)  is  simultaneously
  116.       copied into product register X0 so it can be multiplied by
  117.       k in the next instruction.
  118.  
  119.    6.  The state (X0) is now multiplied by the k coefficient (Y0)
  120.       and added to the old value of T to get the new value of T.
  121.       Simultaneously, the new state variable (A)  is  saved  and
  122.       the  next  k coefficient is obtained.  The pointers R0 and
  123.       R4 are both incremented to point to  the  next  state  and
  124.       coefficient respectively.
  125.  
  126.    7.  Three passes of this  loop  are  made.   The  first  state
  127.       needed  for  the  second  sample is currently saved at the
  128.       first location of the state buffer with the  other  states
  129.       calculated  by  the  loop  saved in consecutive locations.
  130.       The last state that the loop calculates (Sx) is not needed
  131.       for the next sample time.
  132.  
  133.    8.  The result is rounded and the pointer to the state  buffer
  134.       is  backed up by one.  This points the state buffer to the
  135.       unused state (Sx) so that the next sample  is  saved  over
  136.       the  unused  state.  Note that the initial MOVE increments
  137.       the pointer to the k's by one and the loop increments  the
  138.       pointer  three times.  In order to have the pointer to the
  139.       k's pointing to the first coefficient (k1), the modulo  on
  140.       the k pointer is four.
  141.  
  142.     The benchmarks for this  filter  are:   7  instructions,  3N+5
  143.     instruction cycles, 2 stack locations.
  144.  
  145.     An example of how to use this macro is in the DSPLIB in the
  146.     file LATFIR1T.ASM.
  147.